<?php
if (!defined('ipos')) die("Please contact Y!m: ichphien_pro or Email: ichphien_pro@yahoo.com.");
// phÃ¢n trang
function ipos_pages($ttrow,$limit,$page,$url,$type=''){
	$total = ceil($ttrow/$limit);
	if ($total <= 1) return '';
    if ($page<>1){
		//$main .= "<li><a title='Trang Ä‘áº§u' href='".$url."1'>Â« Trang Ä‘áº§u</a></li>";
		if($type == "comment")
			$main .= "<a title='Sau' onclick='commentlist(".$url.','.($page-1).");'>â†�</a>";
		else
			$main .= "<a title='Sau' href='".$url.($page-1)."'>â†�</a>";
    }
	for($num = 1; $num <= $total; $num++){
		if ($num < $page - 1 || $num > $page + 4) 
		continue;
		if($num==$page) 
			$main .= "<a class=\"activer\">$num</a>"; 
        else { 
			if($type == "comment")
		   		$main .= "<a title='Trang $num' onclick='commentlist($url,$num);'>$num</a>";
			else
				$main .= "<a title='Trang $num' href='$url$num'>$num</a>";
       } 		
    }
    if ($page<>$total){
		if($type == "comment")
			$main .= "<a title='Tiáº¿p' onclick='commentlist(".$url.','.($page+1).");'>â†’</a>";
		else
			$main .= "<a title='Tiáº¿p' href='".$url.($page+1)."'>â†’</a>";
		//$main .= "<li><a title='Trang cuá»‘i' href='$url$total'>Trang cuá»‘i</a></li>"; 
    }
  return $main;
}
// kÃ½ tá»±c Ä‘áº·c biá»‡t
function un_htmlchars($str) {
	return str_replace(array('&lt;', '&gt;', '&quot;', '&amp;', '&#92;', '&#39','&#039;'), array('<', '>', '"', '&', chr(92), chr(39), chr(39)), $str);
}
function htmlchars($str) {
	return str_replace(
		array('&', '<', '>', '"', chr(92), chr(39)),
		array('&amp;', '&lt;', '&gt;', '&quot;', '&#92;', '&#39'),
		$str
	);
}
// khÃ´ng dáº¥u
function get_ascii($st){
		$vietChar 	= 'Ã¡|Ã |áº£|Ã£|áº¡|Äƒ|áº¯|áº±|áº³|áºµ|áº·|Ã¢|áº¥|áº§|áº©|áº«|áº­|Ã©|Ã¨|áº»|áº½|áº¹|Ãª|áº¿|á»�|á»ƒ|á»…|á»‡|Ã³|Ã²|á»�|Ãµ|á»�|Æ¡|á»›|á»�|á»Ÿ|á»¡|á»£|Ã´|á»‘|á»“|á»•|á»—|á»™|Ãº|Ã¹|á»§|Å©|á»¥|Æ°|á»©|á»«|á»­|á»¯|á»±|Ã­|Ã¬|á»‰|Ä©|á»‹|Ã½|á»³|á»·|á»¹|á»µ|Ä‘|Ã�|Ã€|áº¢|Ãƒ|áº |Ä‚|áº®|áº°|áº²|áº´|áº¶|Ã‚|áº¤|áº¦|áº¨|áºª|áº¬|Ã‰|Ãˆ|áºº|áº¼|áº¸|ÃŠ|áº¾|á»€|á»‚|á»„|á»†|Ã“|Ã’|á»Ž|Ã•|á»Œ|Æ |á»š|á»œ|á»ž|á» |á»¢|Ã”|á»�|á»’|á»”|á»–|á»˜|Ãš|Ã™|á»¦|Å¨|á»¤|Æ¯|á»¨|á»ª|á»¬|á»®|á»°|Ã�|ÃŒ|á»ˆ|Ä¨|á»Š|Ã�|á»²|á»¶|á»¸|á»´|Ä�';
		$engChar	= 'a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|e|e|e|e|e|e|e|e|e|e|e|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|u|u|u|u|u|u|u|u|u|u|u|i|i|i|i|i|y|y|y|y|y|d|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|E|E|E|E|E|E|E|E|E|E|E|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|U|U|U|U|U|U|U|U|U|U|U|I|I|I|I|I|Y|Y|Y|Y|Y|D';
		$arrVietChar 	= explode("|", $vietChar);
		$arrEngChar		= explode("|", $engChar);
		return str_replace($arrVietChar, $arrEngChar, $st);
	}
// seo
function replace($string) {
	$string = strtolower(get_ascii($string));
    $string = preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'),
        array('', '-', ''), htmlspecialchars_decode($string));
    return $string;
}
function replace_search($string) {
	$string = strtolower(get_ascii($string));
    $string = preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'),
        array('', '%2B', ''), htmlspecialchars_decode($string));
    return $string;
}

/**
 * @copyright 2014 GES Inc, return url film 
 * @author HoangPV
 * @param string $name
 * @param int $id
 * @param int $type
 */
function url_link($name,$id,$type) {
	$name	=	replace($name);
	if($id	== 0)
		$url 	= 	MAIN_URL.'/'.$type.'/'.$name.".html";
	else
		$url 	= 	MAIN_URL.'/'.$type.'/'.$name.'_'.encode_id($id)."/";
	return $url;
}
// kick cá»› áº£nh phim
function film_img($url,$thumb='') {
	if($thumb) {
		$url	=	str_replace("film/","film/",$url);
		$url	=	str_replace("info/","info/",$url);
	}
	return $url;
}
// kick cá»› avatar
function avatar($url,$thumb='') {
	if(!$url)	$url	=	'template/img/no_avatar.jpg';
	else {
		if($thumb)	$url	=	str_replace("avatar/","avatar/thumb/".$thumb,$url);
	}
	return $url;
}

// rut gon
function printstr($str,$len){
	$arrstr = explode(" ",$str);
	$detail = "";
	if(count($arrstr) <= $len)
		$len = count($arrstr);
	else
		$detail  = " ...";
	for($i=0;$i<$len;$i++)
		echo $arrstr[$i]." ";
	echo $detail;
}

// cat chu
function cut($str, $len) {
    $str = trim($str);
    if (strlen($str) <= $len) return $str;
    $str = substr($str, 0, $len);
    if ($str != "") {
        if (!substr_count($str, " ")) return $str." ...";
        while (strlen($str) && ($str[strlen($str) - 1] != " ")) $str = substr($str, 0, -1);
        $str = substr($str, 0, -1)." ...";
    }
    return $str;
}

// check name
function check_name($name) {
	if($name=="")
		$name		=	"Ä�ang cáº­p nháº­t.";
	return $name;
}

// loáº¡i bá»� html
function htmltxt($document){
	$search = array('@<script[^>]*?>.*?</script>@si',  // Strip out javascript
				   '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
				   '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
				   '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments including CDATA
	);
	$text = preg_replace($search, '', $document);
	return $text;
} 
// giÃ m flood
function fooldpost(){
	$_SESSION['current_message_post'] = time();
	$timeDiff_post = $_SESSION['current_message_post'] - $_SESSION['prev_message_post'];
	$floodInterval_post	= 10;
	$wait_post = $floodInterval_post - $timeDiff_post ;	
	if($timeDiff_post <= $floodInterval_post)
	return true;
	else 
	return false;
}
// gá»­i mail
function sendmail($from,$to,$subject,$message) {
	$header = "From: $fromrnReply-to: $from";
	mail($to, $subject, $message, $header);
	return true;
}
//============================================================================
function BANNER($vitri,$width='auto',$height='') {
	global $db;
	$adv = $db->database("adv_name,adv_img,adv_url,adv_phanloai","adv"," adv_vitri = '".$vitri."' AND adv_status = 0 ORDER by adv_id ASC");
	if($adv) {
		for($i=0;$i<count($adv);$i++){
				if($adv[$i][3] == 1) {
					echo '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'.$width.'" height="'.$height.'" id="adv_top" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" /><param name="movie" value="'.$adv[$i][1].'" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="'.$adv[$i][1].'" quality="high" bgcolor="#ffffff" wmode="transparent" width="'.$width.'" height="'.$height.'" name="adv_top" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
				}
				else {
					echo '<a href="'.$adv[$i][2].'" target="_bank"><img alt="'.$adv[$i][0].'" src="'.$adv[$i][1].'" border="0" width="'.$width.'" height="'.$height.'"></a>';
				}
		}

	}
}
function html($url) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_HEADER, 1);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
}
// Giáº£i mÃ£ id bÃ i hÃ¡t
function decode_id($id) {
    $id = str_replace('w',5,$id);
    $id = str_replace('y',4,$id);
    $id = str_replace('o',3,$id);
    $id = str_replace('t',2,$id);
	$id = str_replace('i',1,$id);
    $id = hexdec($id);
	$id = $id - 123456;
	$id = strtoupper($id);
    return strtolower($id);
}
// MÃ£ hÃ³a id bÃ i hÃ¡t
function encode_id($id) {
    $id = dechex($id + 123456);
    $id = str_replace(1,'i',$id);
    $id = str_replace(2,'t',$id);
    $id = str_replace(3,'o',$id);
    $id = str_replace(4,'y',$id);
    $id = str_replace(5,'w',$id); 
	$id = strtoupper($id);
    return strtolower($id);
}
function type_video(&$url) {
	$t_url = strtolower($url);
	$ext = explode('.',$t_url);
	$ext = $ext[count($ext)-1];
	$ext = explode('?',$ext);
	$ext = $ext[0];
	$movie_arr = array(
		'wmv',
		'avi',
		'asf',
		'mpg',
		'mpe',
		'mpeg',
		'asx',
		'm1v',
		'mp2',
		'mpa',
		'ifo',
		'vob',
		'smi',
	);
	
	$extra_swf_arr = array(
		'www.metacafe.com',
		'www.livevideo.com',
	);
	
	for ($i=0;$i<count($extra_swf_arr);$i++){
		if (preg_match("#^http://".$extra_swf_arr[$i]."/(.*?)#s",$url)) {
			$type = 2;
			break;
		}
	}
	$is_youtube = (preg_match("#youtube.com/watch\?v=(.*?)#s",$url));
	$is_youtube1 = (preg_match("#youtube.com/watch%(.*?)#s",$url));
	$is_youtube2 = (preg_match("#youtube.com/watch/v/(.*?)#s",$url));
	$is_youtube3 = (preg_match("#youtube.com/v/(.*?)#s",$url));
	$is_youtube4 = (preg_match("#youtu.be/(.*?)#s",$url));
    $is_gdata = (preg_match("#http://gdata.youtube.com/feeds/api/playlists/(.*?)#s",$url));
	$is_daily = (preg_match("#dailymotion.com#",$url));
	$is_vntube = (preg_match("#http://www.vntube.com/mov/view_video.php\?viewkey=(.*?)#s",$url));
	$is_tamtay = (preg_match("#http://video.tamtay.vn/play/([^/]+)(.*?)#s",$url,$idvideo_tamtay));
	$is_chacha = (preg_match("#http://chacha.vn/song/(.*?)#s",$url));
	$is_clipvn = (preg_match("#phim.clip.vn/watch/([^/]+)/([^,]+),#",$url));
	$is_clipvn1 = (preg_match("#clip.vn/watch/(.*?)#s",$url));	
	$is_clipvn2 = (preg_match('#clip.vn/w/(.*?)#s',$url));
	$is_clipvn3 = (preg_match('#clip.vn/embed/(.*?)#s',$url));
	$is_googleVideo = (preg_match("#http://video.google.com/videoplay\?docid=(.*?)#s",$url));
	$is_myspace = (preg_match("#http://vids.myspace.com/index.cfm\?fuseaction=vids.individual&VideoID=(.*?)#s",$url));
	$is_timnhanh = (preg_match("#http://video.yume.vn/(.*?)#s",$url));
	$is_veoh = (preg_match("#http://www.veoh.com/videos/(.*?)#s",$url));
	$is_veoh1 = (preg_match("#http://www.veoh.com/browse/videos/category/([^/]+)/watch/(.*?)#s",$url));
	$is_baamboo = (preg_match("#http://video.baamboo.com/watch/([0-9]+)/video/([^/]+)/(.*?)#",$url,$idvideo_baamboo));
	$is_livevideo = (preg_match("#http://www.livevideo.com/video/([^/]+)/(.*?)#",$url,$idvideo_live));
	$is_sevenload = (preg_match("#sevenload.com/videos/([^/-]+)-([^/]+)#",$url,$id_sevenload));
	$is_picasa = (preg_match('#picasaweb.google.com/(.*?)#s', $url));
	$is_badongo = (preg_match("#badongo.com/vid/(.*?)#s",$url));
	$id_sevenload = (preg_match("#sevenload.com/videos/([^/-]+)-([^/]+)#",$url,$id_sevenload));
	$is_olala = (preg_match("#http://timvui.vn/player/(.*?)#s",$url));
    $is_zing = (preg_match("#video.zing.vn/([^/]+)#",$url));
	$is_zing1 = (preg_match("#video.zing.vn/video/clip/([^/]+)#",$url));
	$is_zing2 = (preg_match("#mp3.zing.vn/tv/media/([^/]+)#",$url));
	$is_zing3 = (preg_match("#tv.zing.vn/video/([^/]+)#",$url));
    $is_mediafire = (preg_match("#http://www.mediafire.com/?(.*?)#s",$url));
    $is_cyworld = (preg_match("#cyworld.vn/([^/]+)#",$url));
    $is_goonline = (preg_match("#http://clips.goonline.vn/xem/(.*?)#s",$url));
    $is_movshare = (preg_match("#http://www.movshare.net/video/(.*?)#s",$url));
    $is_novamov = (preg_match("#http://www.novamov.com/video/(.*?)#s",$url));
	$is_zippyshare = (preg_match("#http://www([0-9]+).zippyshare.com/v/(.*?)/file.html#s",$url));
	$is_sendspace = (preg_match("#http://www.sendspace.com/file/(.*?)#s",$url,$idvideo_sendspace));
	$is_vidxden = (preg_match("#http://www.vidxden.com/(.*?)#s",$url));
	$is_megafun = (preg_match("##megafun.vn/(.*?)#s",$url));
	$is_BB = (preg_match("#http://www.videobb.com/video/(.*?)#s",$url));
	$is_Sshare = (preg_match("#http://www.speedyshare.com/files/(.*?)#s",$url));
	$is_4share1 = (preg_match("#4shared.com/file/(.*?)#s",$url));
	$is_4share2 = (preg_match("#4shared.com/video/(.*?)#s",$url));
	$is_4share3 = (preg_match("#4shared.com/embed/(.*?)#s",$url));
	$is_2share1 = (preg_match("#2shared.com/file/(.*?)#s",$url));
	$is_2share2 = (preg_match("#2shared.com/video/(.*?)#s",$url));
	$is_2share3 = (preg_match("#2sharedid=(.*?)#s",$url));
	$is_Wootly = (preg_match("#http://www.wootly.com/(.*?)#s",$url));
	$is_tusfiles = (preg_match("#http://www.tusfiles.net/(.*?)#s",$url));
	$is_sharevnn = (preg_match("#http://share.vnn.vn/dl.php/(.*?)#s",$url));
	$is_BBS = (preg_match("#http://videobb.com/video/(.*?)#s",$url));
	$is_ovfile = (preg_match("#http://ovfile.com/(.*?)#s",$url));
	$is_SSh = (preg_match("#http://phim.soha.vn/watch/3/video/(.*?)#s",$url));
	$is_em4share = (preg_match("#http://www.4shared.com/embed/(.*?)#s",$url));
	$is_viddler = (preg_match("#http://www.viddler.com/player/(.*?)#s",$url));
	$is_vivo = (preg_match("#http://vivo.vn/episode/(.*?)#s",$url));
	$is_SeeOn = (preg_match("#http://video.seeon.tv/video/(.*?)#s",$url));
	$is_vidus = (preg_match("#http://s([0-9]+).vidbux.com:([0-9]+)/d/(.*?)#s",$url));
	$is_Twitclips = (preg_match("#http://www.twitvid.com/(.*?)#s",$url));
	$is_videozer = (preg_match("#http://videozer.com/embed/(.*?)#s",$url));
	$is_eyvx = (preg_match("#http://eyvx.com/(.*?)#s",$url));
	$is_banbe = (preg_match("#banbe.net/(.*?)#s",$url));
	$is_nhaccuatui = (preg_match("#nhaccuatui.com(.*?)#s", $url));
	$is_ggdocs = (preg_match("#docs.google.com(.*?)#s", $url));
	$is_tvzing = (preg_match("#tv.zing.vn/video/([^/]+)#",$url));
	$is_upfile = (preg_match("#upfile.vn/([^/]+)#",$url));
	
	if ($ext == 'flv' || $ext == 'mp4') $type = 1;
	elseif ($ext == 'swf' || $is_googleVideo || $is_baamboo) $type = 2;
	elseif ($is_zing || $is_zing1 || $is_zing2 || $is_zing3) $type = 3;
	elseif ($is_youtube || $is_youtube1 || $is_youtube2 || $is_youtube3 || $is_youtube4) $type = 4;
	elseif ($is_picasa) $type = 5;
    elseif ($is_movshare) $type = 6;
	elseif ($is_tamtay || $is_tamtay1 || $idvideo_tamtay || $idvideo_tamtay2) $type = 7;
	elseif ($is_4share1 || $is_4share2 || $is_4share3) $type = 8;
	elseif ($ext == 'divx' || $is_sendspace || $is_olala || $is_megavideo || $is_mediafire || $is_goonline || $is_sevenload || $is_vidxden || $is_novamov || $is_BB || $is_Sshare || $is_Wootly || $is_tusfiles || $is_sharevnn || $is_BBS || $is_ovfile || $is_SSh || $is_em4share || $is_viddler || $is_vivo || $is_SeeOn || $is_vidus || $is_Twitclips || $is_videozer || $is_eyvx || $is_myspace || $is_timnhanh || $is_chacha) $type = 9;
	elseif ($is_2share1 || $is_2share2 || $is_2share3) $type = 10;
	elseif ($is_clipvn || $is_clipvn1 || $is_clipvn2 || $is_clipvn3) $type = 11;
	elseif ($is_banbe) $type = 12;
	elseif ($is_veoh || $is_veoh1) $type = 13;
	elseif ($is_megafun) $type = 14;
	elseif ($is_nhaccuatui) $type = 15;
	elseif ($is_daily) $type = 16; 
	elseif ($is_zippyshare) $type = 17;
	elseif ($is_gdata) $type = 18;
	elseif ($is_cyworld) $type = 19;
	elseif ($is_badongo) $type = 20;
	elseif ($is_ggdocs) $type = 21;
	elseif ($is_tvzing) $type = 22;
	elseif ($is_upfile) $type = 23;
	elseif (!$type) $type = 1;
    return $type;
}
?>